algalcommand.alpha
Class Photobioreactor

java.lang.Object
  extended by algalcommand.alpha.Photobioreactor

public class Photobioreactor
extends java.lang.Object


Field Summary
static java.lang.String COMMAND_PREFIX
          This is the prefix that the PBRBrain uses to differentiate commands from other stuff that it receives from its serial input
static java.lang.String COMMAND_SUFFIX
          The suffix is used by the PBRBrain to know when to parse the input command (actually, the PBRBrain is usually smart enough to not need this, but that behavior is not a design spec., so that may not always be true).
protected  java.io.BufferedReader input
          The input stream is an object for receiving data (usually text) from something else's output.
protected  java.io.PrintWriter output
          The output stream is an object for sending data (usually text) out to a destination (such as a file, or in this case, a network connection).
static int PBR_PORT
          This is the port number for talking to the PBRs
static java.lang.String TAGNAME
           
static int TIMEOUT_MS
           
 
Constructor Summary
Photobioreactor()
          Default constructor, sets all values to null.
Photobioreactor(java.lang.String ipaddress)
          Constructor plus initialization from network address
 
Method Summary
 void addPBRListener(PBRDataListener l)
          Adds a PBRListener to this object.
 java.util.List<Photobioreactor> getByName(java.lang.String name, boolean casesensitive, Photobioreactor... reactors)
          Scans through the given list of photobioreactors and returns all of those whose name matches the given name.
 java.lang.String getMAC()
          The PBRBrain has no way of seeing its own MAC address, but its ethernet module transmits its MAC during network discovery.
 java.lang.String getName()
           
 void initializeFromAddress(java.lang.String ipaddress)
          Initializes this Photobioreactor by connecting it to the provided host address (which presumably is the Lantronix Ethernet module of a PBR).
static void main(java.lang.String[] args)
          just for code testing purposes
 void removeAllPBRListeners()
          Removes all PBRListeners currently registered with this object
 void removePBRListener(PBRDataListener l)
          Removes a PBRListener from this object.
protected  void sendCommand(java.lang.String command)
          Formats the given command to PBR command notation (basically add '>' as a prefix) and sends it down the provided output stream.
protected static void sendCommand(java.lang.String command, java.io.PrintWriter out)
          Formats the given command to PBR command notation (basically add '>' as a prefix) and sends it down the provided output stream
 void setMAC(java.lang.String newmac)
          The PBRBrain has no way of seeing its own MAC address, but its ethernet module transmits its MAC during network discovery.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TAGNAME

public static final java.lang.String TAGNAME
See Also:
Constant Field Values

TIMEOUT_MS

public static final int TIMEOUT_MS
See Also:
Constant Field Values

PBR_PORT

public static final int PBR_PORT
This is the port number for talking to the PBRs

See Also:
Constant Field Values

output

protected java.io.PrintWriter output
The output stream is an object for sending data (usually text) out to a destination (such as a file, or in this case, a network connection).


input

protected java.io.BufferedReader input
The input stream is an object for receiving data (usually text) from something else's output. In this case, our input stream is wrapped in a BufferedReader, which can read ahead of our calls to check what has come in. Very convenient.


COMMAND_PREFIX

public static final java.lang.String COMMAND_PREFIX
This is the prefix that the PBRBrain uses to differentiate commands from other stuff that it receives from its serial input

See Also:
Constant Field Values

COMMAND_SUFFIX

public static final java.lang.String COMMAND_SUFFIX
The suffix is used by the PBRBrain to know when to parse the input command (actually, the PBRBrain is usually smart enough to not need this, but that behavior is not a design spec., so that may not always be true).

See Also:
Constant Field Values
Constructor Detail

Photobioreactor

public Photobioreactor()
Default constructor, sets all values to null. You need to use initializeFromAddress(address) to fill in the values from a network location.


Photobioreactor

public Photobioreactor(java.lang.String ipaddress)
                throws java.net.UnknownHostException,
                       java.io.IOException,
                       java.lang.InterruptedException,
                       java.lang.IllegalArgumentException
Constructor plus initialization from network address

Parameters:
ipaddress - Network address of the PBR unit that this object should represent.
Throws:
java.net.UnknownHostException - If ipaddress was not valid or not found.
java.io.IOException - If errors occurred while trying to communicate with the device.
java.lang.InterruptedException - If this thread was interrupted while trying to connect.
java.lang.IllegalArgumentException - If the device exists, but is not a PBR (it doesn't respond appropriately to PBR commands).
Method Detail

setMAC

public void setMAC(java.lang.String newmac)
The PBRBrain has no way of seeing its own MAC address, but its ethernet module transmits its MAC during network discovery.

Parameters:
newmac - MAC address from the Lantronix module

getMAC

public java.lang.String getMAC()
The PBRBrain has no way of seeing its own MAC address, but its ethernet module transmits its MAC during network discovery.

Returns:
MAC address from the Lantronix module

initializeFromAddress

public final void initializeFromAddress(java.lang.String ipaddress)
                                 throws java.net.UnknownHostException,
                                        java.io.IOException,
                                        java.lang.InterruptedException,
                                        java.lang.IllegalArgumentException
Initializes this Photobioreactor by connecting it to the provided host address (which presumably is the Lantronix Ethernet module of a PBR).

Parameters:
ipaddress - Network address of the PBR unit that this object should represent.
Throws:
java.net.UnknownHostException - If ipaddress was not valid or not found.
java.io.IOException - If errors occurred while trying to communicate with the device.
java.lang.InterruptedException - If this thread was interrupted while trying to connect.
java.lang.IllegalArgumentException - If the device exists, but is not a PBR (it doesn't respond appropriately to PBR commands).

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
A string identifying this PBR using its name, ip address, and hardware address

sendCommand

protected static void sendCommand(java.lang.String command,
                                  java.io.PrintWriter out)
                           throws java.io.IOException
Formats the given command to PBR command notation (basically add '>' as a prefix) and sends it down the provided output stream

Parameters:
command - The command to send (e.g. setSolarLED(2.5));
out - An output stream to the PBR
Throws:
java.io.IOException - thrown if there was a problem with the output stream

sendCommand

protected void sendCommand(java.lang.String command)
Formats the given command to PBR command notation (basically add '>' as a prefix) and sends it down the provided output stream. It checks if the socket is still connected and reconnects if it isn't .

Parameters:
command -
Throws:
java.io.IOException

getByName

public java.util.List<Photobioreactor> getByName(java.lang.String name,
                                                 boolean casesensitive,
                                                 Photobioreactor... reactors)
Scans through the given list of photobioreactors and returns all of those whose name matches the given name.

Parameters:
name - Name of the Photobioreactor that you want to find
casesensitive - Whether or not to match cases
reactors - An array or list of Photobioreactors
Returns:
The sublist of PBRs from the list given that has the matching name, or null if none were found

getName

public java.lang.String getName()
Returns:
The name for this PBR

addPBRListener

public void addPBRListener(PBRDataListener l)
Adds a PBRListener to this object. PBRListeners will be given data every time data is sent from the PBR over the network.

Parameters:
l - A PBRListener object that wants to handle incoming data

removePBRListener

public void removePBRListener(PBRDataListener l)
Removes a PBRListener from this object. PBRListeners will be given data every time data is sent from the PBR over the network.

Parameters:
l - A PBRListener object that was handling incoming data

removeAllPBRListeners

public void removeAllPBRListeners()
Removes all PBRListeners currently registered with this object


main

public static void main(java.lang.String[] args)
just for code testing purposes